<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
		 <meta name="apple-mobile-web-app-capable" content="yes"/>
		 <meta name="format-detection" content="telphone=no, email=no"/>
		 <meta name="HandheldFriendly" content="true"/>
		<meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"/>
		<link th:href="@{/css/userInfo.css}" rel="stylesheet" type="text/css"/>
		<script type="text/javascript" th:src="@{/js/jquery-1.11.3.min.js}"></script>
		<title>信息填写</title>
	</head>
	<body>
	<div class="wrap">
		<input id="url"  type="hidden" th:value="${url}"/>
		<h4>请填写收件人信息：</h4>
		<form id="dataForm" action="">
			<input id="ip" name="ip"  type="hidden" th:value="${ip}"/>
			<div class="input-item">
				<span>姓名：</span>
				<div><input id="userName" name="userName"  type="text" placeholder="请输入姓名"/></div>
			</div>
			<div class="input-item">
				<span>电话：</span>
				<div><input id="phone" name="phone" type="text" placeholder="请输入号码"/></div>
			</div>
			<div class="input-item">
				<span>地址：</span>
				<div><input id="address" name="address" type="text" placeholder="请输入地址" /></div>
			</div>

			<div class="input-time">
				<div>方便听电话时间：</div>
				<div><input id="time" name="time" type="time"  placeholder="请选择时间"/></div>
			</div>
			<div class="submit" onclick="saveInfo();">提交信息</div>
		</form>
	</div>
	<div id="allmap" style="display:none;"></div>


	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&amp;ak=S14rmGSAd2o8x80qt6bbcWWQ5bDGfeGt"></script>


	<script type="text/javascript">
        var SITE_BASE_PATH=getContextPath();
        var flag=true;
        var callbackurl=$("#url").val();
        function getContextPath(){
            var pathName = document.location.pathname;
            var index = pathName.substr(1).indexOf("/");
            var result = pathName.substr(0,index+1);
            return result;
        }


        //baidu
        var map = new BMap.Map("allmap");
        var point = new BMap.Point(116.331398,39.897445);
        map.centerAndZoom(point,12);

        var geolocation = new BMap.Geolocation();
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                var mk = new BMap.Marker(r.point);
                map.addOverlay(mk);
                map.panTo(r.point);
                //alert('经纬度'+r.point.lng+','+r.point.lat);
                var geoc = new BMap.Geocoder();
                geoc.getLocation(r.point, function(rs){
                    var addComp = rs.addressComponents;
                    //alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
                    var curAddress=addComp.province+addComp.city+addComp.district+addComp.street+addComp.streetNumber;
                    $("#address").val(curAddress);

                });

            }
        },{enableHighAccuracy: true})

        //==============================================================


        function saveInfo(){
            if(!flag){
                return false;
            }
            var userName=$("#userName").val();
            var phone=$("#phone").val();
            var address=$("#address").val();
            var time=$("#time").val();

            if($.trim(userName)==""){
                alert('请输入姓名');
                return false;
            }
            if($.trim(phone)==""){
                alert('请输入手机号');
                return false;
            }

            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(phone)) {
                alert('请输入正确的手机号');
                return false;
            }

            if($.trim(address)==""){
                alert('请输入地址');
                return false;
            }
            if($.trim(time)==""){
                alert('请输入方便听电话时间');
                return false;
            }
            flag=false;
            $.ajax({
                type: 'POST',
                url: SITE_BASE_PATH+'/user/add?',
                data : $("#dataForm").serialize(),
                dataType: "json",
                success: function(data){
                    if(data.result >0){
                        alert('信息提交成功');
                        //setTimeout("clear()", 1500);
                    }else{
                        alert('信息提交失败');
                        flag=true;
                    }
                    //回到返回地址todo
                    tocallback();
                },
                error: function(xhr, status, error){
                    alert('出错了');
                    flag=true;
                }
            });

        }



        function tocallback(){

            $.get(callbackurl,function(data,status){

            });


        }


	</script>

	</body>
</html>
